﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace CircleWindow
{
    public class ModuleShowClass : NotifyPropertyChanged
    {
        public ModuleType ModuleType;

        private string _moduleName;
        public string ModuleName
        {
            get { return _moduleName; }
            set
            {
                _moduleName = value;
                RaisePropertyChanged(nameof(ModuleName));
            }
        }

        public int ModuleIndex;

        private ImageSource _resourceImage;
        public ImageSource ResourceImage
        {
            get { return _resourceImage; }
            set
            {
                _resourceImage = value;
                RaisePropertyChanged(nameof(ResourceImage));
            }
        }

        public string ModuleResourceHeader;

        private bool _isFlash;
        public bool IsFlash
        {
            get { return _isFlash; }
            set
            {
                _isFlash = value;
                RaisePropertyChanged(nameof(IsFlash));
            }
        }

        private ModuleStatus _initState = ModuleStatus.Default;
        public ModuleStatus InitState
        {
            get { return _initState; }
            set
            {
                _initState = value;
                ChangeState();
            }
        }

        public ModuleShowClass(ModuleType type, string moduleName, int Index = 1)
        {
            ModuleType = type;
            ModuleName = moduleName;
            ModuleIndex = Index;
            switch (type)
            {
                case ModuleType.Main:
                    ModuleResourceHeader = "WayzimWindow.Monitor.";
                    break;
                case ModuleType.DB:
                case ModuleType.DBConfig:
                    ModuleResourceHeader = "WayzimWindow.DataBinding.";
                    break;
                case ModuleType.BLL:
                case ModuleType.Manual:
                    ModuleResourceHeader = "WayzimWindow.Server.";
                    break;
                case ModuleType.Track:
                    ModuleResourceHeader = "WayzimWindow.Controller.";
                    break;
                case ModuleType.Feeder:
                    ModuleResourceHeader = "WayzimWindow.Feeder.";
                    break;
                case ModuleType.Chute:
                    ModuleResourceHeader = "WayzimWindow.Chute.";
                    break;
                case ModuleType.Camera:
                    ModuleResourceHeader = "WayzimWindow.BarcodeCamera.";
                    break;
                case ModuleType.PLC:
                    ModuleResourceHeader = "WayzimWindow.PLC.";
                    break;
                case ModuleType.GrayCamera:
                    ModuleResourceHeader = "WayzimWindow.GrayCamera.";
                    break;
                case ModuleType.Car:
                    ModuleResourceHeader = "WayzimWindow.Car.";
                    break;
            }
            ResourceImage = (ImageSource)Application.Current.FindResource(ModuleResourceHeader + "Default");
        }

        private void ChangeState()
        {
            try
            {
                switch (_initState)
                {
                    case ModuleStatus.Default:
                        IsFlash = false;
                        ResourceImage = (ImageSource)Application.Current.FindResource(ModuleResourceHeader + "Default");
                        break;
                    case ModuleStatus.Initing:
                        IsFlash = true;
                        ResourceImage = (ImageSource)Application.Current.FindResource(ModuleResourceHeader + "Normal");
                        break;
                    case ModuleStatus.Success:
                        IsFlash = false;
                        ResourceImage = (ImageSource)Application.Current.FindResource(ModuleResourceHeader + "Normal");
                        break;
                    case ModuleStatus.Error:
                        IsFlash = false;
                        ResourceImage = (ImageSource)Application.Current.FindResource(ModuleResourceHeader + "Abnormal");
                        break;
                }
            }
            catch (Exception ex)
            {
                //LogHelper.Instance.Exception(ex.ToString());
            }
        }
    }

    public enum ModuleStatus
    {
        /// <summary>
        /// 默认状态
        /// </summary>
        Default = 0,
        /// <summary>
        /// 初始化中
        /// </summary>
        Initing = 1,
        /// <summary>
        /// 状态正常
        /// </summary>
        Success = 2,
        /// <summary>
        /// 状态异常
        /// </summary>
        Error = 3,
    }

    public enum ModuleType
    {
        /// <summary>
        /// 主控
        /// </summary>
        Main = 0,
        /// <summary>
        /// 配置数据库
        /// </summary>
        DBConfig = 1,
        /// <summary>
        /// 数据库
        /// </summary>
        DB = 2,
        /// <summary>
        /// 业务
        /// </summary>
        BLL = 3,
        /// <summary>
        /// 地控
        /// </summary>
        Track = 4,
        /// <summary>
        /// 供包台
        /// </summary>
        Feeder = 5,
        /// <summary>
        /// 相机
        /// </summary>
        Camera = 6,
        /// <summary>
        /// 下料口
        /// </summary>
        Chute = 7,
        /// <summary>
        /// PLC
        /// </summary>
        PLC = 8,
        /// <summary>
        /// 补码
        /// </summary>
        Manual = 9,
        /// <summary>
        /// 灰度仪
        /// </summary>
        GrayCamera = 10,
        /// <summary>
        /// 车载
        /// </summary>
        Car = 11,
    }
}
